﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Timers;

namespace SensorDetection
{
    class TimeSensor : Sensor
    {
        //private string time;
        private Timer myTimer;
        private const int TIMER_INTERVAL = 1000;
        public TimeSensor()
        {
            name="Time Sensor";
            data = DateTime.Now.TimeOfDay.ToString() + " " + DateTime.Now.DayOfWeek.ToString();
            myTimer = new Timer(); //Initialize Timer
            myTimer.Elapsed += new ElapsedEventHandler(timerEventArrived);
            myTimer.Interval = TIMER_INTERVAL;
            myTimer.Start();
        }
        public string getTime()
        {
            return (string)data;
        }
        public void timerEventArrived(object source, ElapsedEventArgs f)
        {
            data = DateTime.Now.TimeOfDay.ToString() + " " + DateTime.Now.DayOfWeek.ToString();
            Notify();
        }
        public void setTime()
        {
            data = DateTime.Now.TimeOfDay.ToString() + " " + DateTime.Now.DayOfWeek.ToString();
            Notify();
        }
    }
}
